/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package frmsystem;

import java.util.ArrayList;
import java.util.Date;
import java.util.Observable;
import java.util.List;

/**
 *
 * @author bahria
 */
public class Account extends Observable implements IAccount {

    //private properties

    private String accountNo;
    private double interestRate;
    protected double currentAmmount;
    
    public Account(){    	
    }
    
    protected List<IEntry> entries = new ArrayList<IEntry>();
    
    //Interface implementation
    
    public double getBalance() {
        return currentAmmount;
    }
    
    public void setBalance(double amount){
    	currentAmmount = amount;
    }

    public void applyInterest() {
        currentAmmount = currentAmmount + (currentAmmount * (interestRate/100));
    }

    public String getReport(Date startdate, Date enddate) {
        String report = null;
    	for(IEntry entry : entries){
        	if(startdate.after(entry.getDate()) && enddate.before(entry.getDate()))
        		report += entry.toString();
        }
    	return report;
    }
    
    @Override
	public String getReportAll() {
    	String report = null;
    	for(IEntry entry : entries){
        	report += entry.toString();
        }
    	return report;
	}
   

    public void executeTransaction(IEntry entry) {
        entry.execute();
        entries.add(entry);
        this.setChanged();
        this.notifyObservers(this);
    }

    public double getLastTransactionAmount() {
        return entries.get(entries.size()-1).getAmount();        
    }

    //Public Methods

    public String getAccountNo() {
        return accountNo;
    }

    public void setAccountNo(String accountNo) {
        this.accountNo = accountNo;
    }

    public double getCurrentAmmount() {
        return currentAmmount;
    }

    public void setCurrentAmmount(double currentAmmount) {
        this.currentAmmount = currentAmmount;
    }

    public double getInterestRate() {
        return interestRate;
    }

    public void setInterestRate(double interestRate) {
        this.interestRate = interestRate;
    }
    
    //public void GenerateEmail(String subject, String message){
    	///party.generateEmail(subject, message);
    //}

	@Override
	public IEntry getLastTransaction() {

		return entries.get(entries.size()-1);
	}

	@Override
	public void GenerateEmail(String subject, String message) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public String getName(){
		return "Account";
	}
	

}
